package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.ActivityMapper;
import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.businessService.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public ResultJson selectActivityAll(Map map) {
        List selectActivityAll = activityMapper.selectActivityAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectActivityAll != null) {
            resultJson.getSuccess("成功",selectActivityAll);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson selectByIdActivity(Integer id) {
        List selectByIdActivity = activityMapper.selectByIdActivity(id);
        ResultJson resultJson = new ResultJson();
        if (selectByIdActivity !=null){
            resultJson.getSuccess("成功",selectByIdActivity);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson addActivity(Activity activity,Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("activity",activity);
        map.put("login",login );
        int addActivity = activityMapper.addActivity(map);
        ResultJson resultJson = new ResultJson();
        if (addActivity >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateByIdActivity(Integer id) {

        int updateByIdActivity = activityMapper.updateByIdActivity(id);
        ResultJson resultJson = new ResultJson();
        if (updateByIdActivity >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;

    }

    @Override
    public ResultJson deleteByIdActivity(Integer id) {

        int deleteByIdActivity = activityMapper.deleteByIdActivity(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdActivity>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateByIdActivity_introduce1(Integer id) {
        int  updateByIdActivity_introduce1 = activityMapper.updateByIdActivity_introduce1(id);
        ResultJson resultJson = new ResultJson();
        if (updateByIdActivity_introduce1>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateByIdActivity_introduce2(Integer id) {
        int  updateByIdActivity_introduce2 = activityMapper.updateByIdActivity_introduce2(id);
        ResultJson resultJson = new ResultJson();
        if (updateByIdActivity_introduce2>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }


}
